<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Laravel\Lumen\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        'App\Console\Commands\GoodsOrderCancelCommand', //商品订单未支付 订单超过30分钟未付款自动取消
        'App\Console\Commands\TourOrderCancelCommand', //线路订单未支付 订单超过30分钟未付款自动取消
        'App\Console\Commands\LandownersOrderCancelCommand',//做地主订单未支付 订单超过30分钟未付款自动取消
        'App\Console\Commands\TourTuanCommand', //组团失败判定
        'App\Console\Commands\TourTuanRefundCommand',//组团失败退款
        'App\Console\Commands\GoodsOrderConfirmCommand', //商品订单自动收货
        'App\Console\Commands\TourOrderConfirmCommand', //线路订单自动收货
        'App\Console\Commands\LandownersOrderConfirmCommand', //做地主订单自动收货
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {

        $now = local_date('Y-m-d',gmtime()) ;
        $commands_root = storage_path('logs/commands/');
          if(!file_exists($commands_root.'goodsorder_cancel/')){
              mkdir($commands_root.'goodsorder_cancel/',0777,true);
          }
          if(!file_exists($commands_root.'tourorder_cancel/')){
              mkdir($commands_root.'tourorder_cancel/',0777,true);
          }
          if(!file_exists($commands_root.'landownersorder_cancel/')){
              mkdir($commands_root.'landownersorder_cancel/',0777,true);
          }
          if(!file_exists($commands_root.'tour_tuan/')){
              mkdir($commands_root.'tour_tuan/',0777,true);
          }
          if(!file_exists($commands_root.'tourtuan_refund/')){
              mkdir($commands_root.'tourtuan_refund/',0777,true);
          }
          if(!file_exists($commands_root.'goodsorder_confirm/')){
              mkdir($commands_root.'goodsorder_confirm/',0777,true);
          }
          if(!file_exists($commands_root.'tourorder_confirm/')){
              mkdir($commands_root.'tourorder_confirm/',0777,true);
          }
          if(!file_exists($commands_root.'landownersorder_confirm/')){
             mkdir($commands_root.'landownersorder_confirm/',0777,true);
          }

        $schedule->command('xdd:goodsordercancel')->everyFiveMinutes()->appendOutputTo($commands_root.'goodsorder_cancel/'.$now.'.log');
        $schedule->command('xdd:tourordercancel')->everyFiveMinutes()->appendOutputTo($commands_root.'tourorder_cancel/'.$now.'.log');
        $schedule->command('xdd:landownersordercancel')->everyFiveMinutes()->appendOutputTo($commands_root.'landownersorder_cancel/'.$now.'.log');
        $schedule->command('xdd:tourtuan')->everyFiveMinutes()->appendOutputTo($commands_root.'tour_tuan/'.$now.'.log');
        $schedule->command('xdd:tourtuanrefund')->everyFiveMinutes()->appendOutputTo($commands_root.'tourtuan_refund/'.$now.'.log');
        $schedule->command('xdd:goodsorderconfirm')->everyFiveMinutes()->appendOutputTo($commands_root.'goodsorder_confirm/'.$now.'.log');
        $schedule->command('xdd:tourorderconfirm')->everyFiveMinutes()->appendOutputTo($commands_root.'tourorder_confirm/'.$now.'.log');
        $schedule->command('xdd:landownersorderconfirm')->everyFiveMinutes()->appendOutputTo($commands_root.'landownersorder_confirm/'.$now.'.log');
    }
}
